package org.framework.edge.builder.infrastructure.persistence;

import jakarta.annotation.Resource;
import org.framework.edge.builder.domain.model.docker.builder.module.record.DockerBuildModuleRecord;
import org.framework.edge.builder.domain.model.docker.builder.module.record.DockerBuildModuleRecordRepository;
import org.framework.edge.builder.infrastructure.converter.DockerBuildModuleRecordConverter;
import org.framework.edge.builder.infrastructure.entity.DockerBuildModuleRecordDO;
import org.springframework.stereotype.Repository;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;

import java.util.List;
import java.util.stream.Collectors;
/**
 * describe 打包记录 
 *
 * @author Jia wei Wu
 * @date 2024/08/13 07:39 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence 
 **/
@Repository
public class DockerBuildModuleRecordRepositoryImpl  implements  DockerBuildModuleRecordRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增打包记录
     *
     * @param dockerBuildModuleRecord 新增打包记录     
     * @return {@link Result<DockerBuildModuleRecord>} 打包记录新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModuleRecord> story(DockerBuildModuleRecord dockerBuildModuleRecord) {
        DockerBuildModuleRecordDO dockerBuildModuleRecordDO = DockerBuildModuleRecordConverter.INSTANCE.fromDockerBuildModuleRecord(dockerBuildModuleRecord);
        lazyLambdaStream.upsert(dockerBuildModuleRecordDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增打包记录
     *
     * @param dockerBuildModuleRecordList 批量新增打包记录     
     * @return {@link Result<List<DockerBuildModuleRecord>>} 打包记录新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<List<DockerBuildModuleRecord>> batchStory(List<DockerBuildModuleRecord> dockerBuildModuleRecordList) {
        List<DockerBuildModuleRecordDO> dockerBuildModuleRecordDOList = dockerBuildModuleRecordList.stream().map(DockerBuildModuleRecordConverter.INSTANCE::fromDockerBuildModuleRecord).collect(Collectors.toList());
        lazyLambdaStream.upsert(dockerBuildModuleRecordDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个打包记录
     *
     * @param dockerBuildModuleRecord 查询单个打包记录     
     * @return {@link Result<DockerBuildModuleRecord>} 打包记录领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModuleRecord> findOne(DockerBuildModuleRecord dockerBuildModuleRecord) {
        DockerBuildModuleRecordDO dockerBuildModuleRecordDO = DockerBuildModuleRecordConverter.INSTANCE.fromDockerBuildModuleRecord(dockerBuildModuleRecord);
        DockerBuildModuleRecord dockerBuildModuleRecordOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(dockerBuildModuleRecordDO), DockerBuildModuleRecord.class);
        return ResultFactory.successOf(dockerBuildModuleRecordOne);
    }

    /**
     * describe 查询多个打包记录
     *
     * @param dockerBuildModuleRecord 查询多个打包记录     
     * @return {@link Result<List<DockerBuildModuleRecord>>} 打包记录领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<List<DockerBuildModuleRecord>> findList(DockerBuildModuleRecord dockerBuildModuleRecord) {
        DockerBuildModuleRecordDO dockerBuildModuleRecordDO = DockerBuildModuleRecordConverter.INSTANCE.fromDockerBuildModuleRecord(dockerBuildModuleRecord);
        List<DockerBuildModuleRecord> dockerBuildModuleRecordList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(dockerBuildModuleRecordDO), DockerBuildModuleRecord.class);
        return ResultFactory.successOf(dockerBuildModuleRecordList);
    }

    /**
     * describe 分页查询多个打包记录
     *
     * @param size 当前页数
     * @param current 当前页
     * @param dockerBuildModuleRecord 分页查询多个打包记录     
     * @return {@link Result<LazyPage<DockerBuildModuleRecord>>} 分页打包记录领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<LazyPage<DockerBuildModuleRecord>> findPage(int size,int current,DockerBuildModuleRecord dockerBuildModuleRecord) {
        DockerBuildModuleRecordDO dockerBuildModuleRecordDO = DockerBuildModuleRecordConverter.INSTANCE.fromDockerBuildModuleRecord(dockerBuildModuleRecord);
        LazyPage<DockerBuildModuleRecord> lazyPage = new LazyPage<>(current,size);
        LazyPage<DockerBuildModuleRecord> dockerBuildModuleRecordLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(dockerBuildModuleRecordDO),lazyPage, DockerBuildModuleRecord.class);
        return ResultFactory.successOf(dockerBuildModuleRecordLazyPage);
    }

    /**
     * describe 删除打包记录
     *
     * @param dockerBuildModuleRecord 删除打包记录     
     * @return {@link Result<DockerBuildModuleRecord>} 打包记录     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModuleRecord> remove(DockerBuildModuleRecord dockerBuildModuleRecord) {
        DockerBuildModuleRecordDO dockerBuildModuleRecordDO = DockerBuildModuleRecordConverter.INSTANCE.fromDockerBuildModuleRecord(dockerBuildModuleRecord);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(dockerBuildModuleRecordDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在打包记录
     *
     * @param dockerBuildModuleRecord 打包记录领域对象     
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<Boolean> exists(DockerBuildModuleRecord dockerBuildModuleRecord) {
        DockerBuildModuleRecordDO dockerBuildModuleRecordDO = DockerBuildModuleRecordConverter.INSTANCE.fromDockerBuildModuleRecord(dockerBuildModuleRecord);
        Boolean exists=lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(dockerBuildModuleRecordDO));
        return ResultFactory.successOf(exists);
    }

}